What is @thi.ng/api?
@thi.ng/api is a collection of TypeScript interfaces, types, and utility functions for functional programming, event handling, and other common tasks in JavaScript/TypeScript projects.
What are @thi.ng/api's main functionalities?
Event Handling
This feature allows you to create and manage custom events. The code sample demonstrates creating an event, adding a listener, and dispatching the event.
const { Event } = require('@thi.ng/api');
const event = new Event('test');
event.addListener('test', (e) => console.log('Event received:', e));
event.dispatch('test', { message: 'Hello, World!' });
Functional Programming Utilities
This feature provides utility functions for functional programming. The code sample demonstrates filtering an array to get even numbers and then mapping the array to get their squares.
const { map, filter } = require('@thi.ng/api');
const nums = [1, 2, 3, 4, 5];
const evenNums = filter((x) => x % 2 === 0, nums);
const squaredNums = map((x) => x * x, evenNums);
console.log(squaredNums); // [4, 16]
Type Utilities
This feature includes type-checking utilities. The code sample demonstrates checking if a value is a string or a number.
const { isString, isNumber } = require('@thi.ng/api');
console.log(isString('hello')); // true
console.log(isNumber(123)); // true
console.log(isNumber('123')); // false
Other packages similar to @thi.ng/api
lodash
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides similar functional programming utilities like map, filter, and type-checking functions. However, it does not focus on event handling.
rxjs
RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code. It offers more advanced event handling and functional programming utilities compared to @thi.ng/api.
ramda
Ramda is a practical functional library for JavaScript programmers. It focuses on immutability and side-effect-free functions, providing utilities similar to @thi.ng/api's functional programming features.
This project is part of the
@thi.ng/umbrella monorepo.
About
Common, generic types, interfaces & mixins.
This package is implicitly used by most other projects in this
repository. It defines:
- Dozens of generic, common interfaces & types
- Class & method decorators
- Mixins
- Logging
- Assert (can be disabled for production builds)
- Typedarray utilities
Status
STABLE - used in production
Search or submit any issues for this package
Installation
yarn add @thi.ng/api
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/api?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/api/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 2.08 KB / CJS: 2.22 KB / UMD: 2.19 KB
Dependencies
None
API
Generated API docs
Environment variables
The following env variables are used to control the behavior of some functions in production builds:
UMBRELLA_ASSERTS
- if set to 1
the
assert
function will always be enabled. By default, assert()
is
disabled for production builds, i.e. if process.env.NODE_ENV === "production"
.UMBRELLA_GLOBALS
- if set to 1
the
exposeGlobal
function will always be enabled. By default, exposeGlobal()
is
disabled for production builds, i.e. if process.env.NODE_ENV === "production"
.
Authors
Maintainer
Contributors
If this project contributes to an academic publication, please cite it as:
@misc{thing-api,
title = "@thi.ng/api",
author = "Karsten Schmidt and others",
note = "https://thi.ng/api",
year = 2016
}
License
© 2016 - 2021 Karsten Schmidt // Apache Software License 2.0